package com.cabd.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.cabd.staticfinal.DownLoadAndUpLoadPath;

public class XlsxUtils {
	
	public static void changeHeaders(String folderName) throws IOException {
		//处理天气的xlsx文件
		String pathOldWeather = DownLoadAndUpLoadPath.downLoadAndUpLoadPath+"\\"+
		                   folderName+"\\weather.xlsx";
		File fileWeather = new File(pathOldWeather);
		FileInputStream fileInputWeather = new FileInputStream(fileWeather);
		XSSFWorkbook workbookWeather = new XSSFWorkbook(fileInputWeather);
		XSSFSheet xssfSheetWeather = workbookWeather.getSheetAt(0);
		String []weather = {"城市", "天气", "最低气温", "最高气温", "日期"};
		XSSFRow xssfRowWeather = xssfSheetWeather.getRow(0);
		for(int i = 0; i < weather.length; i++){
			XSSFCell xssfCell = xssfRowWeather.getCell(i);
			xssfCell.setCellValue(weather[i]);
		}
		workbookWeather.write(new FileOutputStream(fileWeather));
		fileInputWeather.close();
		//处理特情文件
		String pathOldSpecial = DownLoadAndUpLoadPath.downLoadAndUpLoadPath+"\\"+folderName+"\\special_news.xlsx";
		String []specials = {"特情机场", "收集时间", "开始时间", "结束时间", "特情内容"};
		File fileSpecial = new File(pathOldSpecial);
		FileInputStream fileInputSpecial = new FileInputStream(fileSpecial);
		XSSFWorkbook workbookSpecial = new XSSFWorkbook(fileInputSpecial);
		XSSFSheet xssfSheetSpecial = workbookSpecial.getSheetAt(0);
		XSSFRow xssfRowSpecial = xssfSheetSpecial.getRow(0);
		for(int i = 0; i < specials.length; i++) {
			XSSFCell xssfCell = xssfRowSpecial.getCell(i);
			xssfCell.setCellValue(specials[i]);
		}
		workbookSpecial.write(new FileOutputStream(fileSpecial));
		fileInputSpecial.close();
		
	}
	public static void main(String[] args) throws IOException {
		changeHeaders("aa");
	}
}
